<?php

/**
 * Description of PacksManager_PDO
 *
 * @author FFOZEU
 */
namespace Applications\Modules\Packs\Models;

if( !defined('IN') ) die('Hacking Attempt');

class PacksManager_PDO extends PacksManager{
    
    /*
     * liste les packs
     */
    public function getPacks(){
        
        $sql = 'SELECT id, credits, prix
                FROM '.$this->nameTable.'
                ORDER BY credits';
        
		$requete = $this->dao->query($sql);
        
        return $this->fecthAssoc_data($requete, $this->name);
    }
    /*
     * recherche un pack en fonction de son id
     */
    public function getPackById($id){
        
        return $this->fecthRow_data($this->findById($this->nameTable, $id), $this->name);
    }
    /*
     * ajoute un pack
     */
    public function addPack(array $param){
        $pack = new Packs($param);
        $sql='INSERT INTO '.$this->nameTable.'
              SET credits = :credits, prix = :prix';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':credits',intval($pack->getCredits()));
        $req->bindParam(':prix',intval($pack->getPrix()));
        
        return $req->execute();
    }
    /*
     * met à jour un pack
     */
    public function updatePack(array $param){
        $pack = new Packs($param);
        $sql='UPDATE '.$this->nameTable.'
              SET credits = :credits, prix = :prix
              WHERE id = :id';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':credits',intval($pack->getCredits()));
        $req->bindParam(':prix',intval($pack->getPrix()));
        $req->bindParam(':id',intval($pack->getId()));
        
        return $req->execute();
    }
    /*
     * supprime un pack
     */
    public function delPack(array $id){
        
        return $this->delete($this->nameTable, $id);
    }
}

?>
